/*
 * SimpleProduct.java
 *
 * Created on 13 novembre 2007, 16:11
 */
package com.reimscopie ;

import java.util.* ;


/**
 * This product is only for resale.
 */
public class SimpleProduct extends Product {
  
  // The price of this simple product
  private float price ;
  
  // The current stock of thi simple product
  private int stock ;
  
  
  /**
   * Create a new <code>SimpleProduct</code> instance with all attributes. This
   * object has no image in the database.
   *
   * @param name The name of the product.
   * @param description The description of the product.
   * @param picture The picture of this product.
   * @param valid The product is valid or obsolete.
   * @param price The price of this simple product.
   * @param stock The current stock of this simple product.
   */
  public SimpleProduct(String name,String description,String picture,
      boolean valid,float price,int stock) {
    
    super(name,description,picture,valid) ;
    
    this.price = price ;
    this.stock = stock ;
    
  }
  
  
  /**
   * Create a new <code>SimpleProduct</code> instance with an image in the
   * database.
   *
   * @param id The simple poduct id in the database.
   * @param name The name of the product.
   * @param description The description of the product.
   * @param picture The picture of this product.
   * @param valid The product is valid or obsolete.
   * @param comments The product comments.
   * @param price The price of this simple product.
   * @param stock The current stock of this simple product.
   */
  public SimpleProduct(long id,String name,String description,String picture,
      boolean valid,Comment[] comments,float price,int stock) {
    
    super(id,name,description,picture,valid,comments) ;
    
    this.price     = price ;
    this.stock     = stock ;
    
  }
  
  
  /**
   * Return the price of this single product.
   *
   * @return The price of this product.
   */
  public float getPrice() {
    return price ;
  }
  
  
  /**
   * Return the current stock of this simple product.
   *
   * @return The current stock of this simple product.
   */
  public int getStock() {
    return stock ;
  }
  
  
  /**
   * Set the current stock of this simple product.
   *
   * @param stock The new stock value.
   */
  public void setStock(int stock) {
    this.stock = stock ;
  }
  
  
  /**
   * Return the total cost of one unit of this product.
   *
   * @return The total cost of this product.
   */
  @Override
  public float getTotalCost() {
    return getPrice() ;
  }
  
  
  /**
   * Create a new map with all attributes of this value.
   *
   * @return A string-string map with the named attributes.
   */
  @Override
  public Map<String,String> toMap() {
    
    Map<String,String> map = new LinkedHashMap<String,String>() ;
    
    map.put("name", getName()) ;
    map.put("description", getDescription()) ;
    map.put("picture", getPicture()) ;
    map.put("valid",String.valueOf(isValid())) ;
    map.put("price",String.valueOf(price)) ;
    map.put("stock",String.valueOf(stock)) ;
    
    return map ;
  }
  
}
